Function.prototype.myApply = function (context) {
  context = context || window
  context.fn = this
  let args = [...arguments].slice(1)[0] // 截取之后是数组包着数组 去除这个数组中的第一个元素
  let result = null
  if (args && args.length) {
    result = context.fn(...args)
  } else {
    result = context.fn()
  }
  delete context.fn
  return result
}
function A (n) {
  console.log(this.name);
  console.log(this.age);
  console.log(n);
}
let person = {
  name: '方现伟',
  age: '20'
}
let person1 = {
  name: '方现伟1',
  age: '201',
  fn: function (n) {
    console.log(this.name);
    console.log(this.age);
    console.log(n);
  }
}



Function.prototype.apply2 = function (context) {
  context = context || window
  context.fn = this
  let args = [...arguments].slice(1)[0]
  let res = context.fn(...args)
  delete context.fn
  return res
}
person1.fn.myApply(person, [1])
A.apply2(person, [1])